package kr.hkit.powerjava.chapter22;

import java.util.*;

public class Array {
	public static <T> T getLast(T[]	a){
		return a[a.length-1];
	}
	
	public static <T extends Comparable<T>> T getMax(T[] a) {
		if(a == null || a.length ==0) return null;
			
			T largest = a[0];
			for(int i =0; i<a.length; i++){
				if(largest.compareTo(a[i])<0){
					largest = a[i];
				}
			}
			return largest;
		
			
	}
	
	public static void main(String[] args) {
		String[] language = {"JAVA", "C#", "C++"};
		Integer[] arr = {5,4,3,2,1};
		
		String last = Array.<String>getLast(language);
		System.out.println(last);
		
		int aLast = Array.getLast(arr);
		System.out.println(aLast);
		
		int aMax = Array.getMax(arr);
		System.out.println(Arrays.toString(arr) + "의 배열에서 가장 큰 값은 ? " + aMax);
		
		
		Test[] arrTest = new Test[3];
		arrTest[0] = new Test(5);
		arrTest[1] = new Test(4);
		arrTest[2] = new Test(3);
		
		System.out.println(Array.getMax(arrTest));
		
		
		
	}

}

class Test implements Comparable<Test>{
	private int a;

	public Test(int a) {
		this.a = a;
	}

	public int getA() {
		return a;
	}

	public void setA(int a) {
		this.a = a;
	}
	
	public int compareTo(Test o){
		return a-o.a;
	}
}
